package com.sdy.configcenter.web.config;

import com.alibaba.druid.filter.logging.Slf4jLogFilter;
import com.alibaba.druid.filter.stat.StatFilter;
import com.sdy.mvc.utils.DruidManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;

@Configuration
@ComponentScan(basePackageClasses = {DruidManager.class})
public class DruidConfig {
    @Bean
    public Slf4jLogFilter logFilter() {
        Slf4jLogFilter logFilter = new Slf4jLogFilter();
        logFilter.setStatementLogEnabled(true);
        logFilter.setStatementExecutableSqlLogEnable(true);
        logFilter.setStatementCreateAfterLogEnabled(false);
        logFilter.setStatementCloseAfterLogEnabled(false);
        logFilter.setStatementExecuteAfterLogEnabled(false);
        logFilter.setStatementParameterSetLogEnabled(false);
        logFilter.setStatementPrepareAfterLogEnabled(false);
        logFilter.setConnectionConnectBeforeLogEnabled(false);
        logFilter.setConnectionConnectAfterLogEnabled(false);
        logFilter.setResultSetCloseAfterLogEnabled(false);
        return logFilter;
    }

    @Bean
    public StatFilter statFilter() {
        StatFilter statFilter = new StatFilter();
        statFilter.setLogSlowSql(true);
        statFilter.setSlowSqlMillis(1000);
        statFilter.setMergeSql(true);
        return statFilter;
    }
}
